/proc/self/cwd/external/libavc/common/ih264_buf_mgr.c
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Copyright (C) 2015 The Android Open Source Project |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at: |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | * |
17 | | ***************************************************************************** |
18 | | * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore |
19 | | */ |
20 | | /** |
21 | | ******************************************************************************* |
22 | | * @file |
23 | | * ih264_buf_mgr.c |
24 | | * |
25 | | * @brief |
26 | | * Contains function definitions for buffer management |
27 | | * |
28 | | * @author |
29 | | * Srinivas T |
30 | | * |
31 | | * @par List of Functions: |
32 | | * - ih264_buf_mgr_size() |
33 | | * - ih264_buf_mgr_lock() |
34 | | * - ih264_buf_mgr_unlock() |
35 | | * - ih264_buf_mgr_yield() |
36 | | * - ih264_buf_mgr_free() |
37 | | * - ih264_buf_mgr_init() |
38 | | * - ih264_buf_mgr_add() |
39 | | * - ih264_buf_mgr_get_next_free() |
40 | | * - ih264_buf_mgr_check_free() |
41 | | * - ih264_buf_mgr_set_status() |
42 | | * - ih264_buf_mgr_get_status() |
43 | | * - ih264_buf_mgr_get_buf() |
44 | | * - ih264_buf_mgr_get_bufid() |
45 | | * - ih264_buf_mgr_get_num_active_buf() |
46 | | * |
47 | | * @remarks |
48 | | * None |
49 | | * |
50 | | ******************************************************************************* |
51 | | */ |
52 | | #include <stdio.h> |
53 | | #include <stdlib.h> |
54 | | #include "ih264_typedefs.h" |
55 | | #include "ih264_macros.h" |
56 | | #include "ih264_defs.h" |
57 | | #include "ih264_error.h" |
58 | | #include "ih264_buf_mgr.h" |
59 | | |
60 | | #include "ithread.h" |
61 | | |
62 | | /** |
63 | | ******************************************************************************* |
64 | | * |
65 | | * @brief Returns size for buf queue context. Does not include buf queue buffer |
66 | | * requirements |
67 | | * |
68 | | * @par Description |
69 | | * Returns size for buf queue context. Does not include buf queue buffer |
70 | | * requirements. Buffer size required to store the bufs should be allocated in |
71 | | * addition to the value returned here. |
72 | | * |
73 | | * @returns Size of the buf queue context |
74 | | * |
75 | | * @remarks |
76 | | * |
77 | | ******************************************************************************* |
78 | | */ |
79 | | WORD32 ih264_buf_mgr_size(void) |
80 | 0 | { |
81 | 0 | WORD32 size; |
82 | 0 |
|
83 | 0 | size = sizeof(buf_mgr_t); |
84 | 0 | size += ithread_get_mutex_lock_size(); |
85 | 0 |
|
86 | 0 | return size; |
87 | 0 | } |
88 | | |
89 | | /** |
90 | | ******************************************************************************* |
91 | | * |
92 | | * @brief |
93 | | * Locks the buf_mgr context |
94 | | * |
95 | | * @par Description |
96 | | * Locks the buf_mgr context by calling ithread_mutex_lock() |
97 | | * |
98 | | * @param[in] ps_buf_mgr |
99 | | * Job Queue context |
100 | | * |
101 | | * @returns IH264_FAIL if mutex lock fails else IH264_SUCCESS |
102 | | * |
103 | | * @remarks |
104 | | * |
105 | | ******************************************************************************* |
106 | | */ |
107 | | IH264_ERROR_T ih264_buf_mgr_lock(buf_mgr_t *ps_buf_mgr) |
108 | 91 | { |
109 | 91 | WORD32 retval; |
110 | 91 | retval = ithread_mutex_lock(ps_buf_mgr->pv_mutex); |
111 | 91 | if(retval) |
112 | 0 | { |
113 | 0 | return IH264_FAIL; |
114 | 0 | } |
115 | 91 | return IH264_SUCCESS; |
116 | 91 | } |
117 | | |
118 | | /** |
119 | | ******************************************************************************* |
120 | | * |
121 | | * @brief |
122 | | * Unlocks the buf_mgr context |
123 | | * |
124 | | * @par Description |
125 | | * Unlocks the buf_mgr context by calling ithread_mutex_unlock() |
126 | | * |
127 | | * @param[in] ps_buf_mgr |
128 | | * Job Queue context |
129 | | * |
130 | | * @returns IH264_FAIL if mutex unlock fails else IH264_SUCCESS |
131 | | * |
132 | | * @remarks |
133 | | * |
134 | | ******************************************************************************* |
135 | | */ |
136 | | |
137 | | IH264_ERROR_T ih264_buf_mgr_unlock(buf_mgr_t *ps_buf_mgr) |
138 | 91 | { |
139 | 91 | WORD32 retval; |
140 | 91 | retval = ithread_mutex_unlock(ps_buf_mgr->pv_mutex); |
141 | 91 | if(retval) |
142 | 0 | { |
143 | 0 | return IH264_FAIL; |
144 | 0 | } |
145 | 91 | return IH264_SUCCESS; |
146 | 91 | |
147 | 91 | } |
148 | | /** |
149 | | ******************************************************************************* |
150 | | * |
151 | | * @brief |
152 | | * Yeilds the thread |
153 | | * |
154 | | * @par Description |
155 | | * Unlocks the buf_mgr context by calling |
156 | | * ih264_buf_mgr_unlock(), ithread_yield() and then ih264_buf_mgr_lock() |
157 | | * buf_mgr is unlocked before to ensure the buf_mgr can be accessed by other threads |
158 | | * If unlock is not done before calling yield then no other thread can access |
159 | | * the buf_mgr functions and update buf_mgr. |
160 | | * |
161 | | * @param[in] ps_buf_mgr |
162 | | * Job Queue context |
163 | | * |
164 | | * @returns IH264_FAIL if mutex lock unlock or yield fails else IH264_SUCCESS |
165 | | * |
166 | | * @remarks |
167 | | * |
168 | | ******************************************************************************* |
169 | | */ |
170 | | IH264_ERROR_T ih264_buf_mgr_yield(buf_mgr_t *ps_buf_mgr) |
171 | 0 | { |
172 | 0 |
|
173 | 0 | IH264_ERROR_T ret = IH264_SUCCESS; |
174 | 0 |
|
175 | 0 | IH264_ERROR_T rettmp; |
176 | 0 | rettmp = ih264_buf_mgr_unlock(ps_buf_mgr); |
177 | 0 | RETURN_IF((rettmp != IH264_SUCCESS), rettmp); |
178 | 0 |
|
179 | 0 | //ithread_usleep(10); |
180 | 0 | ithread_yield(); |
181 | 0 |
|
182 | 0 | rettmp = ih264_buf_mgr_lock(ps_buf_mgr); |
183 | 0 | RETURN_IF((rettmp != IH264_SUCCESS), rettmp); |
184 | 0 | return ret; |
185 | 0 | } |
186 | | |
187 | | |
188 | | /** |
189 | | ******************************************************************************* |
190 | | * |
191 | | * @brief free the buf queue pointers |
192 | | * |
193 | | * @par Description |
194 | | * Frees the buf_mgr context |
195 | | * |
196 | | * @param[in] pv_buf |
197 | | * Memoy for buf queue buffer and buf queue context |
198 | | * |
199 | | * @returns Pointer to buf queue context |
200 | | * |
201 | | * @remarks |
202 | | * Since it will be called only once by master thread this is not thread safe. |
203 | | * |
204 | | ******************************************************************************* |
205 | | */ |
206 | | IH264_ERROR_T ih264_buf_mgr_free(buf_mgr_t *ps_buf_mgr) |
207 | 0 | { |
208 | 0 | WORD32 ret; |
209 | 0 | ret = ithread_mutex_destroy(ps_buf_mgr->pv_mutex); |
210 | 0 |
|
211 | 0 | if(0 == ret) |
212 | 0 | return IH264_SUCCESS; |
213 | 0 | else |
214 | 0 | return IH264_FAIL; |
215 | 0 | } |
216 | | /** |
217 | | ******************************************************************************* |
218 | | * |
219 | | * @brief |
220 | | * Buffer manager initialization function. |
221 | | * |
222 | | * @par Description: |
223 | | * Initializes the buffer manager structure |
224 | | * |
225 | | * @param[in] ps_buf_mgr |
226 | | * Pointer to the buffer manager |
227 | | * |
228 | | * @returns |
229 | | * |
230 | | * @remarks |
231 | | * None |
232 | | * |
233 | | ******************************************************************************* |
234 | | */ |
235 | | |
236 | | |
237 | | void *ih264_buf_mgr_init(void *pv_buf) |
238 | 2 | { |
239 | 2 | WORD32 id; |
240 | 2 | UWORD8 *pu1_buf; |
241 | 2 | buf_mgr_t *ps_buf_mgr; |
242 | 2 | pu1_buf = (UWORD8 *)pv_buf; |
243 | 2 | |
244 | 2 | ps_buf_mgr = (buf_mgr_t *)pu1_buf; |
245 | 2 | pu1_buf += sizeof(buf_mgr_t); |
246 | 2 | |
247 | 2 | ps_buf_mgr->pv_mutex = pu1_buf; |
248 | 2 | pu1_buf += ithread_get_mutex_lock_size(); |
249 | 2 | |
250 | 2 | ithread_mutex_init(ps_buf_mgr->pv_mutex); |
251 | 2 | |
252 | 2 | ps_buf_mgr->i4_max_buf_cnt = BUF_MGR_MAX_CNT; |
253 | 2 | ps_buf_mgr->i4_active_buf_cnt = 0; |
254 | 2 | |
255 | 130 | for(id = 0; id < BUF_MGR_MAX_CNT; id++) |
256 | 128 | { |
257 | 128 | ps_buf_mgr->au4_status[id] = 0; |
258 | 128 | ps_buf_mgr->apv_ptr[id] = NULL; |
259 | 128 | } |
260 | 2 | |
261 | 2 | return ps_buf_mgr; |
262 | 2 | } |
263 | | |
264 | | |
265 | | /** |
266 | | ******************************************************************************* |
267 | | * |
268 | | * @brief |
269 | | * Adds and increments the buffer and buffer count. |
270 | | * |
271 | | * @par Description: |
272 | | * Adds a buffer to the buffer manager if it is not already present and |
273 | | * increments the active buffer count |
274 | | * |
275 | | * @param[in] ps_buf_mgr |
276 | | * Pointer to the buffer manager |
277 | | * |
278 | | * @param[in] pv_ptr |
279 | | * Pointer to the buffer to be added |
280 | | * |
281 | | * @returns Returns 0 on success, -1 otherwise |
282 | | * |
283 | | * @remarks |
284 | | * None |
285 | | * |
286 | | ******************************************************************************* |
287 | | */ |
288 | | IH264_ERROR_T ih264_buf_mgr_add(buf_mgr_t *ps_buf_mgr, |
289 | | void *pv_ptr, |
290 | | WORD32 buf_id) |
291 | 7 | { |
292 | 7 | |
293 | 7 | IH264_ERROR_T ret = IH264_SUCCESS; |
294 | 7 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
295 | 7 | RETURN_IF((ret != IH264_SUCCESS), ret); |
296 | 7 | |
297 | 7 | /* Check if buffer ID is within allowed range */ |
298 | 7 | if(buf_id >= ps_buf_mgr->i4_max_buf_cnt) |
299 | 0 | { |
300 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
301 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
302 | 0 |
|
303 | 0 | return IH264_FAIL; |
304 | 7 | } |
305 | 7 | |
306 | 7 | /* Check if the current ID is being used to hold some other buffer */ |
307 | 7 | if((ps_buf_mgr->apv_ptr[buf_id] != NULL) && |
308 | 7 | (ps_buf_mgr->apv_ptr[buf_id] !=pv_ptr)) |
309 | 0 | { |
310 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
311 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
312 | 0 |
|
313 | 0 | return IH264_FAIL; |
314 | 7 | } |
315 | 7 | ps_buf_mgr->apv_ptr[buf_id] = pv_ptr; |
316 | 7 | ps_buf_mgr->i4_active_buf_cnt++; |
317 | 7 | |
318 | 7 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
319 | 7 | RETURN_IF((ret != IH264_SUCCESS), ret); |
320 | 7 | |
321 | 7 | return ret; |
322 | 7 | } |
323 | | |
324 | | /** |
325 | | ******************************************************************************* |
326 | | * |
327 | | * @brief |
328 | | * Gets the next free buffer. |
329 | | * |
330 | | * @par Description: |
331 | | * Returns the next free buffer available and sets the corresponding status |
332 | | * to DEC |
333 | | * |
334 | | * @param[in] ps_buf_mgr |
335 | | * Pointer to the buffer manager |
336 | | * |
337 | | * @param[in] pi4_buf_id |
338 | | * Pointer to the id of the free buffer |
339 | | * |
340 | | * @returns Pointer to the free buffer |
341 | | * |
342 | | * @remarks |
343 | | * None |
344 | | * |
345 | | ******************************************************************************* |
346 | | */ |
347 | | void* ih264_buf_mgr_get_next_free(buf_mgr_t *ps_buf_mgr, WORD32 *pi4_buf_id) |
348 | 22 | { |
349 | 22 | WORD32 id; |
350 | 22 | void *pv_ret_ptr; |
351 | 22 | IH264_ERROR_T ret = IH264_SUCCESS; |
352 | 22 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
353 | 22 | RETURN_IF((ret != IH264_SUCCESS), NULL); |
354 | 22 | |
355 | 22 | pv_ret_ptr = NULL; |
356 | 37 | for(id = 0; id < ps_buf_mgr->i4_active_buf_cnt; id++) |
357 | 37 | { |
358 | 37 | /* Check if the buffer is non-null and status is zero */ |
359 | 37 | if((ps_buf_mgr->au4_status[id] == 0) && (ps_buf_mgr->apv_ptr[id])) |
360 | 22 | { |
361 | 22 | *pi4_buf_id = id; |
362 | 22 | /* DEC is set to 1 */ |
363 | 22 | ps_buf_mgr->au4_status[id] = 1; |
364 | 22 | pv_ret_ptr = ps_buf_mgr->apv_ptr[id]; |
365 | 22 | break; |
366 | 22 | } |
367 | 37 | } |
368 | 22 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
369 | 22 | RETURN_IF((ret != IH264_SUCCESS), NULL); |
370 | 22 | |
371 | 22 | return pv_ret_ptr; |
372 | 22 | } |
373 | | |
374 | | |
375 | | /** |
376 | | ******************************************************************************* |
377 | | * |
378 | | * @brief |
379 | | * Checks the buffer manager for free buffers available. |
380 | | * |
381 | | * @par Description: |
382 | | * Checks if there are any free buffers available |
383 | | * |
384 | | * @param[in] ps_buf_mgr |
385 | | * Pointer to the buffer manager |
386 | | * |
387 | | * @returns Returns 0 if available, -1 otherwise |
388 | | * |
389 | | * @remarks |
390 | | * None |
391 | | * |
392 | | ******************************************************************************* |
393 | | */ |
394 | | IH264_ERROR_T ih264_buf_mgr_check_free(buf_mgr_t *ps_buf_mgr) |
395 | 0 | { |
396 | 0 | WORD32 id; |
397 | 0 | IH264_ERROR_T ret = IH264_SUCCESS; |
398 | 0 | IH264_ERROR_T rettmp = IH264_SUCCESS; |
399 | 0 | rettmp = ih264_buf_mgr_lock(ps_buf_mgr); |
400 | 0 | RETURN_IF((rettmp != IH264_SUCCESS), ret); |
401 | 0 |
|
402 | 0 | ret = IH264_FAIL; |
403 | 0 | for(id = 0; id < ps_buf_mgr->i4_active_buf_cnt; id++) |
404 | 0 | { |
405 | 0 | if((ps_buf_mgr->au4_status[id] == 0) && |
406 | 0 | (ps_buf_mgr->apv_ptr[id])) |
407 | 0 | { |
408 | 0 | ret = IH264_SUCCESS; |
409 | 0 | break; |
410 | 0 | } |
411 | 0 | } |
412 | 0 | rettmp = ih264_buf_mgr_unlock(ps_buf_mgr); |
413 | 0 | RETURN_IF((rettmp != IH264_SUCCESS), ret); |
414 | 0 |
|
415 | 0 | return ret; |
416 | 0 |
|
417 | 0 | } |
418 | | |
419 | | |
420 | | /** |
421 | | ******************************************************************************* |
422 | | * |
423 | | * @brief |
424 | | * Resets the status bits. |
425 | | * |
426 | | * @par Description: |
427 | | * resets the status bits that the mask contains (status corresponding to |
428 | | * the id) |
429 | | * |
430 | | * @param[in] ps_buf_mgr |
431 | | * Pointer to the buffer manager |
432 | | * |
433 | | * @param[in] buf_id |
434 | | * ID of the buffer status to be released |
435 | | * |
436 | | * @param[in] mask |
437 | | * Contains the bits that are to be reset |
438 | | * |
439 | | * @returns 0 if success, -1 otherwise |
440 | | * |
441 | | * @remarks |
442 | | * None |
443 | | * |
444 | | ******************************************************************************* |
445 | | */ |
446 | | IH264_ERROR_T ih264_buf_mgr_release(buf_mgr_t *ps_buf_mgr, |
447 | | WORD32 buf_id, |
448 | | UWORD32 mask) |
449 | 29 | { |
450 | 29 | IH264_ERROR_T ret = IH264_SUCCESS; |
451 | 29 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
452 | 29 | RETURN_IF((ret != IH264_SUCCESS), ret); |
453 | 29 | |
454 | 29 | |
455 | 29 | /* If the given id is pointing to an id which is not yet added */ |
456 | 29 | if(buf_id >= ps_buf_mgr->i4_active_buf_cnt) |
457 | 0 | { |
458 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
459 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
460 | 0 | return IH264_FAIL; |
461 | 29 | } |
462 | 29 | |
463 | 29 | ps_buf_mgr->au4_status[buf_id] &= ~mask; |
464 | 29 | |
465 | 29 | |
466 | 29 | /* If both the REF and DISP are zero, DEC is set to zero */ |
467 | 29 | if(ps_buf_mgr->au4_status[buf_id] == 1) |
468 | 19 | { |
469 | 19 | ps_buf_mgr->au4_status[buf_id] = 0; |
470 | 19 | } |
471 | 29 | |
472 | 29 | |
473 | 29 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
474 | 29 | RETURN_IF((ret != IH264_SUCCESS), ret); |
475 | 29 | |
476 | 29 | return ret; |
477 | 29 | } |
478 | | |
479 | | |
480 | | /** |
481 | | ******************************************************************************* |
482 | | * |
483 | | * @brief |
484 | | * Sets the status bit. |
485 | | * |
486 | | * @par Description: |
487 | | * sets the status bits that the mask contains (status corresponding to the |
488 | | * id) |
489 | | * |
490 | | * |
491 | | * @param[in] ps_buf_mgr |
492 | | * Pointer to the buffer manager |
493 | | * |
494 | | * @param[in] buf_id |
495 | | * ID of the buffer whose status needs to be modified |
496 | | * |
497 | | * |
498 | | * @param[in] mask |
499 | | * Contains the bits that are to be set |
500 | | * |
501 | | * @returns 0 if success, -1 otherwise |
502 | | * |
503 | | * @remarks |
504 | | * None |
505 | | * |
506 | | ******************************************************************************* |
507 | | */ |
508 | | IH264_ERROR_T ih264_buf_mgr_set_status(buf_mgr_t *ps_buf_mgr, |
509 | | WORD32 buf_id, |
510 | | UWORD32 mask) |
511 | 33 | { |
512 | 33 | IH264_ERROR_T ret = IH264_SUCCESS; |
513 | 33 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
514 | 33 | RETURN_IF((ret != IH264_SUCCESS), ret); |
515 | 33 | |
516 | 33 | if(buf_id >= ps_buf_mgr->i4_active_buf_cnt) |
517 | 0 | { |
518 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
519 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
520 | 0 | return IH264_FAIL; |
521 | 33 | } |
522 | 33 | |
523 | 33 | |
524 | 33 | if((ps_buf_mgr->au4_status[buf_id] & mask) != 0) |
525 | 0 | { |
526 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
527 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
528 | 0 | return IH264_FAIL; |
529 | 33 | } |
530 | 33 | |
531 | 33 | ps_buf_mgr->au4_status[buf_id] |= mask; |
532 | 33 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
533 | 33 | RETURN_IF((ret != IH264_SUCCESS), ret); |
534 | 33 | |
535 | 33 | return ret; |
536 | 33 | } |
537 | | |
538 | | |
539 | | /** |
540 | | ******************************************************************************* |
541 | | * |
542 | | * @brief |
543 | | * Returns the status of the buffer. |
544 | | * |
545 | | * @par Description: |
546 | | * Returns the status of the buffer corresponding to the id |
547 | | * |
548 | | * @param[in] ps_buf_mgr |
549 | | * Pointer to the buffer manager |
550 | | * |
551 | | * @param[in] buf_id |
552 | | * ID of the buffer status required |
553 | | * |
554 | | * @returns Status of the buffer corresponding to the id |
555 | | * |
556 | | * @remarks |
557 | | * None |
558 | | * |
559 | | ******************************************************************************* |
560 | | */ |
561 | | WORD32 ih264_buf_mgr_get_status( buf_mgr_t *ps_buf_mgr, WORD32 buf_id ) |
562 | 0 | { |
563 | 0 | IH264_ERROR_T ret = IH264_SUCCESS; |
564 | 0 | UWORD32 status; |
565 | 0 |
|
566 | 0 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
567 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
568 | 0 |
|
569 | 0 | status = ps_buf_mgr->au4_status[buf_id]; |
570 | 0 |
|
571 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
572 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
573 | 0 |
|
574 | 0 | return status; |
575 | 0 | } |
576 | | |
577 | | |
578 | | /** |
579 | | ******************************************************************************* |
580 | | * |
581 | | * @brief |
582 | | * Gets the buffer from the buffer manager |
583 | | * |
584 | | * @par Description: |
585 | | * Returns the pointer to the buffer corresponding to the id |
586 | | * |
587 | | * @param[in] ps_buf_mgr |
588 | | * Pointer to the buffer manager |
589 | | * |
590 | | * @param[in] buf_id |
591 | | * ID of the buffer required |
592 | | * |
593 | | * @returns Pointer to the buffer required |
594 | | * |
595 | | * @remarks |
596 | | * None |
597 | | * |
598 | | ******************************************************************************* |
599 | | */ |
600 | | void* ih264_buf_mgr_get_buf(buf_mgr_t *ps_buf_mgr, WORD32 buf_id) |
601 | 0 | { |
602 | 0 | IH264_ERROR_T ret = IH264_SUCCESS; |
603 | 0 | void *pv_buf; |
604 | 0 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
605 | 0 | RETURN_IF((ret != IH264_SUCCESS), NULL); |
606 | 0 |
|
607 | 0 | pv_buf = ps_buf_mgr->apv_ptr[buf_id]; |
608 | 0 |
|
609 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
610 | 0 | RETURN_IF((ret != IH264_SUCCESS), NULL); |
611 | 0 |
|
612 | 0 | return pv_buf; |
613 | 0 | } |
614 | | |
615 | | |
616 | | /** |
617 | | ******************************************************************************* |
618 | | * |
619 | | * @brief |
620 | | * Gets the buffer id from the buffer manager if the buffer is added to the |
621 | | * buffer manager |
622 | | * |
623 | | * @par Description: |
624 | | * Returns the buffer id corresponding to the given buffer if it exists |
625 | | * |
626 | | * @param[in] ps_buf_mgr |
627 | | * Pointer to the buffer manager |
628 | | * |
629 | | * @param[in] pv_buf |
630 | | * Pointer to the buffer |
631 | | * |
632 | | * @returns Buffer id if exists, else -1 |
633 | | * |
634 | | * @remarks |
635 | | * None |
636 | | * |
637 | | ******************************************************************************* |
638 | | */ |
639 | | WORD32 ih264_buf_mgr_get_bufid(buf_mgr_t *ps_buf_mgr, void *pv_buf) |
640 | 0 | { |
641 | 0 | WORD32 id; |
642 | 0 | WORD32 buf_id = -1; |
643 | 0 | IH264_ERROR_T ret = IH264_SUCCESS; |
644 | 0 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
645 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
646 | 0 |
|
647 | 0 | for(id = 0; id < ps_buf_mgr->i4_active_buf_cnt; id++) |
648 | 0 | { |
649 | 0 | if(ps_buf_mgr->apv_ptr[id] == pv_buf) |
650 | 0 | { |
651 | 0 | buf_id = id; |
652 | 0 | break; |
653 | 0 | } |
654 | 0 | } |
655 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
656 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
657 | 0 |
|
658 | 0 | return buf_id; |
659 | 0 | } |
660 | | |
661 | | |
662 | | /** |
663 | | ******************************************************************************* |
664 | | * |
665 | | * @brief |
666 | | * Gets the no.of active buffer |
667 | | * |
668 | | * @par Description: |
669 | | * Return the number of active buffers in the buffer manager |
670 | | * |
671 | | * @param[in] ps_buf_mgr |
672 | | * Pointer to the buffer manager |
673 | | * |
674 | | * @returns number of active buffers |
675 | | * |
676 | | * @remarks |
677 | | * None |
678 | | * |
679 | | ******************************************************************************* |
680 | | */ |
681 | | UWORD32 ih264_buf_mgr_get_num_active_buf(buf_mgr_t *ps_buf_mgr) |
682 | 0 | { |
683 | 0 | UWORD32 u4_buf_cnt; |
684 | 0 | IH264_ERROR_T ret = IH264_SUCCESS; |
685 | 0 |
|
686 | 0 | u4_buf_cnt = 0; |
687 | 0 |
|
688 | 0 | ret = ih264_buf_mgr_lock(ps_buf_mgr); |
689 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
690 | 0 | u4_buf_cnt = ps_buf_mgr->i4_active_buf_cnt; |
691 | 0 |
|
692 | 0 | ret = ih264_buf_mgr_unlock(ps_buf_mgr); |
693 | 0 | RETURN_IF((ret != IH264_SUCCESS), ret); |
694 | 0 |
|
695 | 0 | return u4_buf_cnt; |
696 | 0 | } |